<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <div id="app">
      <button-counter></button-counter>
      <button-counter></button-counter>
      <button-counter></button-counter>
    </div>

    <script src="../../Vue.js"></script>
    <script>
      Vue.component("button-counter", {
        // 组件的data必须要写成函数返回对象
        // 是因为函数有作用域，可以让我们的组件维护自己的状态(data的数据)

        // 每一个组件必须只能有一个根元素(虚拟dom)
        data() {
          return {
            count: 0,
          };
        },
        // data: {
        //   count: 0,
        // },
        template: `
          <div>
            <button @click="fn">++</button>
            <p>点击了{{ count }}次</p>
          </div>
        `,
        methods: {
          fn() {
            this.count++;
          },
        },
      });

      new Vue({
        el: "#app",
        data: {},
      });
    </script>
  </body>
</html>
